
var noticList = $(".get-notic-button");
var stateMap = {"error":"#FFE3E3","warning":"#FFF9DB","normal":"#FAFAFA"};

for (var i = 0; i < noticList.length; i++) {
    $(noticList[i]).click(function () {
        var $this = $(this);
        $.ajax({
            url:"/notic/getOne",
            type:"post",
            dataType:"json",
            data:{
                "noticId":$this.parent().siblings(":first").text()
            },
            success:function (data) {
                $("#batch-notic-get-button").click();
                loadNoticModalBatch(data.notic);
                // var dataList = JSON.parse(data.notic.data);
                // console.log(dataList.timeList);
                // console.log(dataList.datasList);
            }
        });
    });
}

//清空模态框中的信息
function clearNoticModalBatch() {
    $("#noticModal_title_batch").empty();
    $("#noticModal_info_batch").empty();
}

//加载模态框中的信息
function loadNoticModalBatch(data){
    clearNoticModalBatch();
    $("#noticModal_title_batch").append(data.title);
    $("#noticModal_info_batch").append(data.info)
    var list = JSON.parse(data.data);
    if (list == null){
        $("#batch-notic-chart-card").hide();
        return;
    }
    $("#batch-notic-chart-card").show();
    var dataChart = document.getElementById("notic_data_chart_batch");
    $(dataChart).parent().parent().css("background",stateMap[data.noticState]);
    echarts.init(dataChart).setOption({
        color:['#FF0000','#01B468','#4472C5','#ED7C30','#FF8096','#800080'],
        title: [{
            left:400,
            text:data.parm.name
        },{
            left:500,
            text:'上限'+data.parm.max+data.parm.unit
        },{
            left:640,
            text:'下限'+data.parm.min+data.parm.unit
        }],
        animation: false,
        tooltip: {},
        // legend: {
        //     data:["处理后"],
        // },
        xAxis: {
            axisTick: {
                show: false
            },
            axisLine: {
                show: false
            },
            data: list.timeList,
        },
        yAxis: {
            scale: true,
            axisTick: {
                show: false
            },
            axisLine: {
                show: false
            },
        },
        grid: {
            top:40,
            left: 20,
            right: 10,
            bottom: 20,
            width:'auto',
            height:'auto'
        },
        series: [
            {
                name: '处理后',
                type: 'line',
                itemStyle: {
                    normal: {
                        label:{
                            show: true,
                        },
                    },
                    lineStyle:{
                        color:'#01B468'
                    }
                },
                data: list.datasList,
            },
        ]
    });
}

//显示新建推送模态框
function showNewNoticModal() {
    emptyNewNoticModal()
    $("#newNotic-button").click();
    
}

//清空新建推送模态框
function emptyNewNoticModal() {
    $("#new-notic-title").val("");
    $("#new-notic-info").val("");
}

//发送一个推送
function sendOneNotic() {
    $.ajax({
        url:"/notic/send",
        type:"post",
        dataType:"json",
        data:{
            "title":$("#new-notic-title").val(),
            "info":$("#new-notic-info").val(),
            "state":$("input[name='new-notic-state']:checked").val(),
            "authority":$("input[name='new-notic-authority']:checked").val()
        },
        success:function (data) {
            console.log(data)
        }
    });
    // console.log($("#new-notic-title").val());
    // console.log($("#new-notic-info").val());
    // console.log($("input[name='new-notic-state']:checked").val());
    // console.log($("input[name='new-notic-authority']:checked").val());
}

